package com.jianbo.proxy.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
 
public class FileTraversal {
    public static void main(String[] args) {
        String folderPath = "D:/www/jianbo_plus/java/lowcode-boot-v3/lowcode-demo/i_smarthttp/conf"; // 文件夹路径
        File folder = new File(folderPath);
        traverseFiles(folder);
    }
 
    public static List<File> traverseFiles(File folder) {
        List<File> fileList = new ArrayList<>();
        Stack<File> stack = new Stack<>();
        stack.push(folder);
 
        while (!stack.isEmpty()) {
            File currentFile = stack.pop();
 
            if (currentFile.isDirectory()) {
                File[] files = currentFile.listFiles();
                if (files != null) {
                    for (File file : files) {
                        stack.push(file);
                    }
                }
            } else {
                // System.out.println(currentFile.getPath()); // 输出文件名
                fileList.add(currentFile);
            }
        }
        return fileList;
    }
}
